package com.cater.sys.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cater.annotation.SystemServiceLog;
import com.cater.common.BaseEntity;
import com.cater.query.CommonQuery;
import com.cater.sys.dao.DepDao;
import com.cater.sys.entity.Dep;

@Service("depService")
public class DepService {

	@Autowired
	private DepDao depMapper;

	/**
	 * 查询全部部门
	 * 
	 * @return
	 */
	@SystemServiceLog(description = "查询全部部门")
	public List<Dep> getAll() {
		return depMapper.getAll();
	}

	@SystemServiceLog(description = "根据公司ID查询部门")
	public List<Dep> getAllbypid(Integer depid) {
		return depMapper.getAllbypid(depid);
	}

	@SystemServiceLog(description = "根据父ID查询部门")
	public List<Dep> getdepBypid(Integer pid, CommonQuery query) {
		return depMapper.getdepBypid(pid, query);
	}

	/**
	 * 根据ID查询部门
	 * 
	 * @return
	 */
	@SystemServiceLog(description = "根据ID查询部门")
	public Dep getByid(Integer depId) {
		return depMapper.getById(depId);
	}

	/**
	 * 根据用户ID查询部门
	 * 
	 * @param userId
	 * @return
	 */
	@SystemServiceLog(description = "查询用户所属部门")
	public Dep getpidByuser(Integer userId) {
		return depMapper.getpidByuser(userId);
	}

	@SystemServiceLog(description = "添加公司或部门")
	public int save(Dep dep) {
		BaseEntity.getCreate(dep);
		depMapper.save(dep);
		return dep.getDepId();
	}

	@SystemServiceLog(description = "删除公司或部门")
	public int delete(Integer depid) {
		return depMapper.delete(depid);
	}

	@SystemServiceLog(description = "删除部门")
	public void deletestate(Integer depid) {
		depMapper.deletestate(depid);
	}

	@SystemServiceLog(description = "修改部门")
	public void update(Dep dep) {
		BaseEntity.getupdate(dep);
		depMapper.update(dep);
	}

	@SystemServiceLog(description = "获得所有公司")
	public List<Dep> getAllCompany(CommonQuery query) {
		return depMapper.getAllCommon(query);
	}
}
